{# SPDX-License-Identifier: Apache-2.0 -#}

{% macro summary(page) -%}
  Showing {{ page.first_item }} to {{ page.last_item }} of {{ page.item_count }} entries
{% endmacro %}

{% macro paginate(page) -%}
{% if page.items and page.page_count > 1 %}
  {% set map = page.link_map() %}

  <ul class="pagination">
    {# previous button #}
    <li class="page-item previous{% if map.current_page.value == map.first_page.number %} disabled{% endif %}">
        <a href="{{ map.previous_page.href }}" class="page-link">Previous</a>
    </li>

    {# show first page button - special case #}
    {% if map.current_page.value > map.first_page.number + map.radius %}
    <li class="page-item"><a href="{{ map.first_page.href }}" class="page-link">{{ map.first_page.number }}</a></li>
    {% endif %}

    {% for p in map.range_pages %}
      {% if p.type == "current_page" %}
      <li class="page-item active"><a href="{{ p.href }}" class="page-link">{{ p.number }}</a></li>
      {% elif p.type == "page" %}
      <li class="page-item"><a href="{{ p.href }}" class="page-link">{{ p.number }}</a></li>
      {% elif p.type == "span" %}
      <li class="page-item disabled"><a class="page-link">...</a></li>
      {% endif %}
    {% endfor %}

    {# show last page button - special case #}
    {% if map.current_page.value < map.last_page.number - map.radius %}
    <li class="page-item"><a href="{{ map.last_page.href }}" class="page-link">{{ map.last_page.number }}</a></li>
    {% endif %}

    {# "next" button #}
    <li class="page-item next{% if map.current_page.value == map.last_page.number %} disabled{% endif %}">
        <a href="{{ map.next_page.href }}" class="page-link">Next</a>
    </li>
  </ul>
{% endif %}
{%- endmacro %}
